package test
{
import com.adobe.nativeExtensions.AdBanner;
import com.adobe.nativeExtensions.AdBannerEvent;
import com.adobe.nativeExtensions.AdBannerPosition;
import com.devilishgames.air.extensions.admob.ios.AdMob;

import flash.display.Sprite;
import flash.geom.Point;
import flash.text.TextField;

/**
 * 
 * @author waitingsnow
 * $Id: TestAD.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class TestAD extends Sprite
{
	public function TestAD()
	{
		super();
		
		initDisplay();
	}
	
	private var tf:TextField;
	private var adMob:AdMob;
	
	private function initDisplay():void
	{
		try {
			log("adMob init");
			adMob = new AdMob(); // Instanciamos la clase AdMob
			//			adMob.id = "ID DE ADMOB"; // Indicar el ID de la APP de AdMob
			adMob.size = AdMob.GAD_SIZE_728x90; // Indicamos el tamaño del Banner
			adMob.position = new Point(0, stage.stageHeight - adMob.size.y); // Indicamos la posición del banner
			adMob.testMode = true; // Decimos que no use el modo test
			adMob.showAdMob(); // Mostramos el banner
		} catch (e:Error) {
			log("error: " + e.getStackTrace());
		}
		
		AdBanner.adView.startShowingAds(AdBannerPosition.TOP, false);  
		AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADED, adLoaded);  
		AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADING_FAILED, adFailed)
		AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_STARTING, adStart);  
		AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_FINISHED, adFinished); 
	}
	
	private function adLoaded(event:AdBannerEvent):void
	{
		log("Ad Loaded");         
		AdBanner.adView.visible = true;         
		log("leaving: " + event.leaving); 
	}
	
	private function adFailed(event:AdBannerEvent):void
	{
		log("Loaded Failded: " + event.errorCode);
		AdBanner.adView.visible = false;
	}
	
	private function adStart(event:AdBannerEvent):void
	{
		log("Starting");
		log(stage.orientation);
	}
	
	private function adFinished(event:AdBannerEvent):void
	{
		log("Finished");
		log(stage.orientation);
	}
	
	private function log(msg:String):void
	{
		if (!tf)
		{
			tf = new TextField();
			tf.multiline = tf.wordWrap = true;
			tf.width = 300;
			tf.x = tf.y = 100;
			addChild(tf);
		}
		trace(msg);
		tf.appendText(msg + "\n");
	}
}
}